exports.bargain_comment = function (req, res) {

    //获取restful参数
    var restfulParams = req.routeInfo.restfulParams;

    //最终结果
    var resultData = {};

    var activityCommentData = 0;

    var skip = restfulParams.skip == undefined ? 0 : restfulParams.skip;

    var limit = restfulParams.limit == undefined ? config.publicConfig.LIMIT : restfulParams.limit;

    //任务流创建
    async.waterfall([
            //获取我的砍价信息
            function (cb) {

                ////console.log(CORE_APIConfig.coreAPI.searchBargainJoinUserInfo + "/bj_uid/" + restfulParams.u_id + "/bj_oaid/" + restfulParams.oa_id)

                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.searchBargainJoinUserInfo + "/bj_uid/" + restfulParams.u_id + "/bj_oaid/" + restfulParams.oa_id,
                        method: 'GET',
                    },
                    function (err, data) {
                        //console.log(data);
                        //判断是否有错误信息
                        if (err) {
                            return cb(err, data);
                        }


                        //判断该用户是否参与砍价活动了
                        if (data.data.length <= 0) {

                            resultData.isParticipate = false;
                            cb();
                            //RES.response(res, true, resultData);
                        } else {
                            resultData.joinData = data.data[0];
                            resultData.isParticipate = true;
                            cb();
                        }

                    }
                );
            },
            //讨论区
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.activity_comment_info + "/oac_is_reply/0/oac_oaid/" + restfulParams.oa_id + "/skip/" + skip + "/limit/" + limit,
                        method: 'POST',
                        data: {
                            fields: ["oac_id", "oac_uid", "oac_content", "u_nickname", "u_header_url", "oac_zan_count", "oac_comment_time"].join(",")
                        }
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return cb(err, data);
                        }
                        activityCommentData = data.data;

                        resultData.activityCommentData = activityCommentData;

                        cb();
                    }
                );

            },
            function (cb) {

                //创建添加任务
                var tasks = [];

                //循环节点列表
                activityCommentData.forEach(function (item, i) {

                    //创建每一个插入任务
                    tasks.push(function (cb) {

                        if (activityCommentData.length > 0) {
                            // if(item.oac_uid>0){
                            R.SEND_HTTP(
                                req,
                                {
                                    url: CORE_APIConfig.coreAPI.activity_comment_info + "/count/1/oac_oaid/" + restfulParams.oa_id + "/oac_fid/" + item.oac_id,
                                    method: 'POST',
                                    data: {
                                        fields: ["oac_content", "u_nickname"].join(",")
                                    }
                                },
                                function (err, data) {

                                    //console.log(data);

                                    item.reply = data.data;
                                    item.replyCount = data.count;

                                    cb();
                                }
                            );
                            /*}else{
                                cb();
                            }*/
                        } else {
                            cb();
                        }

                    });

                });

                async.waterfall(tasks, cb);

            },





        ], function (err, result) {

            //返回最终拼接结果
            RES.response(res, true, resultData);

        }
    );

};